
Explosion = {}
Explosion.mt = { __index = Explosion }
setmetatable(Explosion, Fire.mt)

function Explosion.initialize(center_x, center_y, radius, damage, force)


	local EXPLOSION_t = Fire.new()
	setmetatable(EXPLOSION_t, Explosion.mt)
	
	EXPLOSION_t.x = center_x
	EXPLOSION_t.y = center_y
	EXPLOSION_t.radius = radius
	EXPLOSION_t.damage = damage
	EXPLOSION_t.force = force
	EXPLOSION_t.prop = MOAIProp2D.new()
	



	return EXPLOSION_t

end


function Explosion.new(center_x, center_y, radius, damage, force)

	local o = Explosion.initialize(center_x, center_y, radius, damage, force)

	return o

end


function Explosion:impact(tar_x, tar_y, rad, damage, f )

	local exp_func = function(self, tar_x, tar_y, rad, damage, f)
		require('mobdebug').on()
		local lives = LifeManager.lifeforms
		local structs = ConstructManager.constructs
		
		local dmg = self.damage
		local force = self.force
		local radius = self.radius
		local x = self.x
		local y = self.y
		
		if tar_x then x = tar_x end
		if tar_y then y = tar_y end
		if rad then radius = rad end
		if damage then dmg = damage end
		if f then force = f end
		
		print("EXPLOSION at x: " .. x .. " y: " .. y )
		
		for i = 1, #lives do
			if lives[i].health then
			
				local a = lives[i].prop:inside(x, y, 0)
				local b
			
			end
		
		end
		
		for i = 1, #structs do
		
			--[===[
			if structs[i].parts  then
				local s_trans = structs[i].transform
				for j = 1 , #structs[i].parts do
					local part = structs[i].parts[j]
				
					--print("EXPLOSION impact #structs part loc:")					
					local x2, y2 = part.prop:getLoc()
					--print(x2, y2)
					
					--print("EXPLOSION impact #structs model to world:")					
					local x3, y3 = part.prop:modelToWorld(x, y)
					--print(x3, y3)
					
					--print("EXPLOSION impact #structs transform loc: ")
					local xt, yt = s_trans:getLoc()
					--print(xt, yt)
					local a
					if part.prop.inside then
						a = part.prop:inside(x,y)
					end
					local b
					
					if a then 
						b = "true"
						print("EXPLOSION inside a : " .. b)
					end
					
					
					
				end
			
			end
			]===]
			
			if structs[i].transform then
				local x2, y2 = structs[i].transform:getLoc()
				--print("EXPLOSION struct transform x : " .. x2 .. " y : " .. y2)
				--print("EXPLOSION x : " .. x .. " y : " .. y )
				if x2 == x and y2 == y then
				
					print("EXPLOSION at TRANSFORM")
					structs[i]:take_damage(dmg)
				
				end
			
			end
		
		end
	end
	
	local t_func = MOAICoroutine.new()
	t_func:run(exp_func, self, tar_x, tar_y, rad, damage, f)


end



return Explosion